#pragma once

#include "Containers/SharedObjectPtr.h"
#include "Containers/String.h"

#include "Widgets/Widget.h"
#include "Font/StaticTextArranger.h"

#include "Font/Font.h"

#include "Misc/StdHead.h"

#include "Texture/Texture2D.h"
#include "Render/Widget/RenderWidgets.h"

#include "TextWidget.m.h"

class RMaterial;


//text widget display text
//if don't set width constriant, widget will use text size as width
//if don't set height constriant, widget will use text size as height
RCLASS()
class WHENGINE_API RTextWidget: public RWidget
{
    ROBJECT
public:    
    RTextWidget();

    RFIELD()
    TWidgetAttribute<CString> Text;
    
    RFIELD()
    TWidgetAttribute<SColor> Color=SColor(1,1,1,1);
    
    RFIELD()
    TWidgetAttribute<TSharedObjectPtr<RFont>> Font;
    
    //height of char image, in pixel
    RFIELD()
    TWidgetAttribute<int64_t> FontSize=16;

    //wrap text when text is too long
    RFIELD()
    TWidgetAttribute<ETextWrapMethod> Wrap=ETextWrapMethod::None;
    
    RFIELD()
    TWidgetAttribute<ETextHorizontalAlignment>HorizontalAlignment= ETextHorizontalAlignment::Left;
    
    RFIELD()
    TWidgetAttribute<ETextVerticalAlignment> VerticalAlignment=ETextVerticalAlignment::Top;

    //get text size last frame
    SVec2 GetTextSize();

protected:
    void PaintSelf(uint16_t& InZOrder,const SRect& InClipArea) override;

    virtual void CalculatePresentPositionAndSize() override;

    void ArrangeGlyphs();

    virtual float CalculateContentWidth() override;
    virtual float CalculateContentHeight() override;

    float GetLineHeight();

    CStaticTextArranger TextArranger;

    TSharedObjectPtr<RFont> GetRenderingFont();
};